//
//  JWFindBusinessActivityVC.m
//  jinwang
//
//  Created by jzb on 2018/3/31.
//  Copyright © 2018年 jzb. All rights reserved.
//


#import "JWFindBusinessActivityVC.h"
#import "ReleaseBoJianVC.h"
#import "JWFBFacadeVC.h"

@interface JWFindBusinessActivityVC ()

//
@property (nonatomic,strong) UIButton *photoBtn;
//筛选
@property (nonatomic,strong) UIButton *shaixuanBtn;

@property (nonatomic, strong) MLMSegmentHead *segHead;
@property (nonatomic, strong) MLMSegmentScroll *segScroll;
@property (nonatomic, strong) TYAlertController *alertController;

@property (nonatomic, strong) UIView *TabbarItemLine;
@property (nonatomic,strong) NSArray *listArr;

@end

@implementation JWFindBusinessActivityVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
        self.title = @"商家动态";
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"back_common"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(goBack)];
    UIBarButtonItem *photoItem = [[UIBarButtonItem alloc]initWithCustomView:self.photoBtn];
    
    self.navigationItem.leftBarButtonItems = @[backItem,photoItem];
    
    UIBarButtonItem *shaixuanItem = [[UIBarButtonItem alloc]initWithCustomView:self.shaixuanBtn];
    self.navigationItem.rightBarButtonItem = shaixuanItem;
    
    _listArr = @[@"门面",@"公司",@"电商",@"小摊",@"自产"];
    _segHead = [[MLMSegmentHead alloc] initWithFrame:CGRM(0, 64*2, 750, 88) titles:_listArr headStyle:SegmentHeadStyleLine layoutStyle:MLMSegmentLayoutDefault];
    //    _segHead.fontScale = 1.1;
    _segHead.fontSize = 17;
    _segHead.deSelectColor = kRGBColor(80, 80, 80);
    _segHead.selectColor = UIColorHex(0xEEA72B);
    _segHead.lineScale = .5;
    _segHead.bottomLineHeight = .5;
    _segHead.lineColor = UIColorHex(0xEEA72B);
    _segHead.bottomLineColor = kRGBColor(230, 230, 230);
    
    _segScroll = [[MLMSegmentScroll alloc] initWithFrame:CGRM(0, 88+64*2, 750, 1334-88-64*2-50*2) vcOrViews:[self vcArr:_listArr.count]];
    
    _segScroll.loadAll = YES;
    _segScroll.showIndex = 0;
    
    _segScroll.backgroundColor = [UIColor whiteColor];
    
    [MLMSegmentManager associateHead:_segHead withScroll:_segScroll completion:^{
        
        [self.view addSubview:_segHead];
        [self.view addSubview:_segScroll];
    }];
    [self DynamicTabbarBuild];
    
}

- (void)DynamicTabbarBuild{
    
    NSArray *BtnTitleArr = @[@"人气",@"普通",@"VIP",@"SVIP",@"关注"];
    
    UIView *TabbarView = [[UIView alloc]initWithFrame:CGRM(0, 1334-100, 750, 100)];
    TabbarView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:TabbarView];
    UIView *TabbarViewLine = [[UIView alloc]initWithFrame:CGRM(0, 0, 750, 1)];
    TabbarViewLine.backgroundColor = [UIColor lightGrayColor];
    [TabbarView addSubview:TabbarViewLine];
    for (int i = 0; i < BtnTitleArr.count; i++) {
        UIButton *TabbarItem = [[UIButton alloc]initWithFrame:CGRM(750/5*i, 1, 750/5, 47.5*2)];
        //        TabbarItem.backgroundColor = [UIColor purpleColor];
        [TabbarItem setTitle:BtnTitleArr[i] forState:UIControlStateNormal];
        [TabbarItem setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
        [TabbarItem addTarget:self action:@selector(TabbarItemOnclick:) forControlEvents:UIControlEventTouchUpInside];
        TabbarItem.tag = 1010 + i;
        if (i == 0) {
            [TabbarItem setTitleColor:UIColorHex(0xEEA72B) forState:UIControlStateNormal];
        }
        [TabbarView addSubview:TabbarItem];
    }
    _TabbarItemLine = [[UIView alloc]initWithFrame:CGRM(10*2, 48*2, 750/5-20*2, 2*2)];
    _TabbarItemLine.backgroundColor = UIColorHex(0xEEA72B);
    [TabbarView addSubview:_TabbarItemLine];
    
}
- (void)TabbarItemOnclick:(UIButton *)sender{
    
    BOOL isLogin = [[ToolManager sharedManager] checkLoginStateAtVC:self];
    
    if (isLogin) {
        if (sender.tag == 1015) {
            
//            JWFindUserBoJianVC *vc = [JWFindUserBoJianVC new];
//            vc.title = @"我的博见";
//            [self.navigationController pushViewController:vc animated:YES];
            
        }else{
            UIButton *button01 = (UIButton *)[self.view viewWithTag:1010];
            UIButton *button02 = (UIButton *)[self.view viewWithTag:1011];
            UIButton *button03 = (UIButton *)[self.view viewWithTag:1012];
            UIButton *button04 = (UIButton *)[self.view viewWithTag:1013];
            UIButton *button05 = (UIButton *)[self.view viewWithTag:1014];
            UIButton *button06 = (UIButton *)[self.view viewWithTag:1015];
            
            [button01 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
            [button02 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
            [button03 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
            [button04 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
            [button05 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
            [button06 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
            [sender setTitleColor:UIColorHex(0xEEA72B) forState:UIControlStateNormal];
            _TabbarItemLine.frame = CGRM(10*2+(750/5)*(sender.tag-1010), 48*2, 750/5-20*2, 2*2);
//            NSMutableDictionary *dict =[[NSMutableDictionary alloc] init];
//            [dict setValue:[NSString stringWithFormat:@"%ld",sender.tag - 1010] forKey:@"post_cate"];
//            
//            NSNotification *notification =[NSNotification notificationWithName:@"JWBJDynamicNotification" object:nil userInfo:dict];
//            
//            [[NSNotificationCenter defaultCenter] postNotification:notification];
        }
        
    }
}
#pragma mark -懒加载
- (UIButton *)photoBtn{
    if (!_photoBtn) {
        _photoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _photoBtn.frame = CGRectMake(0, 0, 44, 44);
        [_photoBtn setImage:[UIImage imageNamed:@"jw_find_dingwei"] forState:UIControlStateNormal];
        [_photoBtn addTarget:self action:@selector(photoButOnclick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _photoBtn;
}
#pragma mark -懒加载
- (UIButton *)shaixuanBtn{
    if (!_shaixuanBtn) {
        _shaixuanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _shaixuanBtn.frame = CGRectMake(0, 0, 44, 44);
        [_shaixuanBtn setImage:[UIImage imageNamed:@"jw_bojian_shaixuan"] forState:UIControlStateNormal];
//        [_shaixuanBtn addTarget:self action:@selector(shaixuanBtnOnclick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _shaixuanBtn;
}
- (void)photoButOnclick:(UIButton *)sender{
    BOOL isLogin = [[ToolManager sharedManager] checkLoginStateAtVC:self];
    
    if (isLogin) {
//        ReleaseBoJianVC *VC = [ReleaseBoJianVC new];
//
//        [self.navigationController pushViewController:VC animated:YES];
    }
    
}

#pragma mark - 数据源
- (NSArray *)vcArr:(NSInteger)count {
    NSMutableArray *arr = [NSMutableArray array];
    
    for (int i = 0; i < _listArr.count; i++) {
        
//        [self makeUrl_Dynamic_defaultTagParent_id:i+1];
        
        JWFBFacadeVC *FacadeVC = [[JWFBFacadeVC alloc]init];
        
        FacadeVC.parent_id = [NSString stringWithFormat:@"%d",i+1];
        [arr addObject:FacadeVC];
        
    }
    
    return arr;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
